package sis.utiltest;/*
* @auther 顶风少年 
* @mail dfsn19970313@foxmail.com
* @date 2019-07-31 19:38
* @notify 
* @version 1.0
*/

import junit.framework.TestCase;
import sis.util.StringUtil;

import java.util.ArrayList;
import java.util.List;

public class StringUtilTest extends TestCase {
    private static final String TEXT = "this is it, isn't it";
    public void testOccurrencesOne(){
        assertEquals(1, StringUtil.occurrences(TEXT,"his"));
    }

    public void testOccurrencesNone(){
        assertEquals(0,StringUtil.occurrences(TEXT,"smelt"));
    }

    public void testOccurrencesMany(){
        assertEquals(3,StringUtil.occurrences(TEXT,"is"));
        assertEquals(2,StringUtil.occurrences(TEXT,"it"));
    }

    public void testOccurrencesSearchStringToolLarge(){
        assertEquals(0,StringUtil.occurrences(TEXT,"sdfas"));
    }

    public void testConcatenateList(){
        List<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        String output = StringUtil.concatenate(list);
        assertEquals(String.format("a%nb%n"),output);
    }

    public void testConcatenateFormattedIntegers(){
        List<Integer>list = new ArrayList<>();
        list.add(12);
        list.add(17);
        String output = StringUtil.concatenateNumbers(list,0);
        assertEquals(String.format("12%n17%n"),output);
    }
}
